###
@ngdoc function
@name xoceanApp.controller:MainCtrl
@description
# MainCtrl
Controller of homepage
###
angular.module("xoceanApp").controller "MainCtrl", ($stateParams, $scope, $filter, Template, ngDialog, templates) ->

  $scope.bgClass = (new Date()).getDate()%6


  $scope.watchVideo = ->
    ngDialog.open({
      template: 'dialog7'
      scope: $scope
      className: 'ngdialog-theme-default ngdialog-vedio'
    })
    return

  $scope.templates = $filter('orderBy')(templates, 'count', true).slice(0, 4)
  _index = 0

  $scope.tmplDetail = (index)->
    _index = index
    $scope.tmpl = $scope.templates[index]
    ngDialog.open({
      template: 'dialog4'
      scope: $scope
      className: 'ngdialog-template-preview'
    })
    return

  $scope.prev = ()->
    return if _index is 0
    _index--
    $scope.tmpl = $scope.templates[_index]
    return

  $scope.next = ()->
    return if _index is $scope.templates.length - 1
    _index++
    $scope.tmpl = $scope.templates[_index]
    return
    
  return
